package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.SearchMaterialEntity3;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class MaterialHomeAdapter extends BaseRecycleAdapter<SearchMaterialEntity3> {

    private TextView price_view;
    private TextView tv_rmb;
    private TextView tv_xiegang;
    private TextView tv_unit;
    private ImageView tag_cuxiao;
    private ImageView self_support;
    private TextView tvStorageName;

    public MaterialHomeAdapter(Context context, List<SearchMaterialEntity3> datas) {
        super(context, R.layout.item_goods_home, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SearchMaterialEntity3 entity) {
        holder.setBinding(BR.viewModel, entity);
        price_view = holder.itemView.findViewById(R.id.price_view);
        tv_rmb = holder.itemView.findViewById(R.id.tv_rmb);
        tv_xiegang = holder.itemView.findViewById(R.id.tv_xiegang);
        tv_unit = holder.itemView.findViewById(R.id.tv_unit);
        tag_cuxiao = holder.itemView.findViewById(R.id.tag_cuxiao);
        self_support = holder.itemView.findViewById(R.id.self_support);
        tvStorageName = holder.itemView.findViewById(R.id.tv_storage_name);

        if (entity.getPromoteStatus() == 2) {
            price_view.setText(entity.getPromotePrice());
            tag_cuxiao.setVisibility(View.VISIBLE);
            price_view.setTextColor(context.getResources().getColor(R.color.new_org));
            tv_rmb.setTextColor(context.getResources().getColor(R.color.new_org));
            tv_xiegang.setTextColor(context.getResources().getColor(R.color.new_org));
            tv_unit.setTextColor(context.getResources().getColor(R.color.new_org));
        } else {
            price_view.setText(entity.getPrice());
            tag_cuxiao.setVisibility(View.GONE);
            price_view.setTextColor(context.getResources().getColor(R.color.new_org2));
            tv_rmb.setTextColor(context.getResources().getColor(R.color.new_org2));
            tv_xiegang.setTextColor(context.getResources().getColor(R.color.new_org2));
            tv_unit.setTextColor(context.getResources().getColor(R.color.new_org2));
        }

        if ("1".equals(entity.getSelfSupportTag())) {
            self_support.setVisibility(View.VISIBLE);
        } else {
            self_support.setVisibility(View.INVISIBLE);
        }

        tvStorageName.setText("仓储:" + entity.getStorageName());
    }
}
